﻿package com.athena.controller
{	
	import com.athena.vo.Chess;
	import com.athena.process.*;
	public class S_Controller {
		
		function S_Controller() { }
		public static function Search_Chess(hor : int, ver : int) {
			for (var i:int = 0; i < ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess.length; i++) 
			{
				if (ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess[i].Status == 1) continue ;
				if ((ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess[i].Hor == hor) && (ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess[i].Ver == ver)) {
					ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess_Movie[i].gotoAndStop(3) ;
					break ;
				}							
			}
		}
		public static function Valid(obj : Chess) {
			var hor : int = obj.Hor ;
			var ver : int = obj.Ver ;
			//Phai Tren
			if (((hor == 9) && (ver == 3)) || ((hor == 8) && (ver == 4))) {
				if (ProcessInTable.ArrCheck[hor - 1][ver + 1] == 0) {
					Cocaro.mainStage_mc["Checked" + (hor - 1).toString() + (ver + 1).toString() + "_mc"].visible = true ;
					Cocaro.mainStage_mc["Checked" + (hor - 1).toString() + (ver + 1).toString() + "_mc"].over_mc.visible = false ;
				} else if (ProcessInTable.ArrCheck[hor - 1][ver + 1] != obj.Color)
					Search_Chess(hor - 1, ver + 1) ;
			}
			//Trai Tren
			if (((hor == 9) && (ver == 5)) || ((hor == 8) && (ver == 4))) {
				if (ProcessInTable.ArrCheck[hor - 1][ver - 1] == 0){
					Cocaro.mainStage_mc["Checked" + (hor - 1).toString() + (ver - 1).toString() + "_mc"].visible = true ;
					Cocaro.mainStage_mc["Checked" + (hor - 1).toString() + (ver - 1).toString() + "_mc"].over_mc.visible = false ;
				} else if (ProcessInTable.ArrCheck[hor - 1][ver - 1] != obj.Color)
					Search_Chess(hor - 1, ver - 1) ;
			}
			//Trai Duoi
			if (((hor == 7) && (ver == 5)) || ((hor == 8) && (ver == 4))) {
				//ProcessInTable.tf.appendText("==>SyTD:" + ProcessInTable.ArrCheck[hor + 1][ver - 1]) ;
				if (ProcessInTable.ArrCheck[hor + 1][ver - 1] == 0) {
					Cocaro.mainStage_mc["Checked" + (hor + 1).toString() + (ver - 1).toString() + "_mc"].visible = true ;
					Cocaro.mainStage_mc["Checked" + (hor + 1).toString() + (ver - 1).toString() + "_mc"].over_mc.visible = false ;
				} else if (ProcessInTable.ArrCheck[hor + 1][ver - 1] != obj.Color)
					Search_Chess(hor + 1, ver -1) ;
			}
			
			//Phai Duoi
			if (((hor == 7) && (ver == 3)) || ((hor == 8) && (ver == 4))) {
				//ProcessInTable.tf.appendText("==>SyPD:" + ProcessInTable.ArrCheck[hor + 1][ver + 1]) ;
				if (ProcessInTable.ArrCheck[hor + 1][ver + 1] == 0) {
					Cocaro.mainStage_mc["Checked" + (hor + 1).toString() + (ver + 1).toString() + "_mc"].visible = true ;
					Cocaro.mainStage_mc["Checked" + (hor + 1).toString() + (ver + 1).toString() + "_mc"].over_mc.visible = false ;
				} else if (ProcessInTable.ArrCheck[hor + 1][ver + 1] != obj.Color)
					Search_Chess(hor + 1, ver + 1) ;
			}			
		}
	}
}